/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import com.opensymphony.xwork2.ActionSupport;
import entity.Event;
import model.bll.EventBLL;

/**
 *
 * @author Hailk_c00639
 */
public class AddEventAction extends ActionSupport {
    private Event event;
    
    public AddEventAction() {
    }
    
    @Override
    public String execute() throws Exception {
        new EventBLL().insertEvent(event);
        
        return SUCCESS;
    }

    @Override
    public void validate(){
        if(event.getEventName().length() == 0)
        {
            addFieldError("event.eventName", "Event name is required.");
        }
        if(event.getFieldName().length() == 0)
        {
            addFieldError("event.fieldName", "Field name is required.");
        }
        if(event.getCreatedDate().toString().isEmpty() == true)
        {
            addFieldError("event.createdDate", "Created date is required.");
        }
        if(event.getStartDate().toString().isEmpty() == true)
        {
            addFieldError("event.startDate", "Start date is required.");
        }
        if(event.getFinishDate().toString().isEmpty() == true)
        {
            addFieldError("event.finishDate", "Finish date is required.");
        }
        
        if(event.getAddress().length() == 0)
        {
            addFieldError("event.address", "Address is required.");
        }
        if(event.getSpeakerName().length() == 0)
        {
            addFieldError("event.speakerName", "Speaker name is required.");
        }
        if(event.getImageUrl().length() == 0)
        {
            addFieldError("event.imageUrl", "Image url is required.");
        }
        if(event.getDescription().length() == 0)
        {
            addFieldError("event.description", "Description is required.");
        }
        if(event.getFee() == 0)
        {
            addFieldError("event.fee", "Fee is required.");
        }
        if(event.getEventStatus().length() == 0)
        {
            addFieldError("event.eventStatus", "Event status is required.");
        }
    }
    
    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }
}